<?php

/**
 * Created by PhpStorm.
 * User: steven
 * Date: 2016/4/20
 * Time: 22:59
 */
class SignatureClass
{
    protected $CI;

    // We'll use a constructor, as you can't directly call a function
    // from a property definition.
    public function __construct()
    {
        // Assign the CodeIgniter super-object
        $this->CI =& get_instance();
        $this->CI->load->model('Jsapi_Ticket_Model');
       // $this->CI->load->library('AccessTokenClass');
        $this->CI->load->library('JsapiTicketClass');
        $this->CI->load->helper('url_helper');
        $this->CI->load->library('session');
    }

    public function generate_signature(){
        $url=$this->CI->session->userdata('uri');
        $url=$url;
        $ticket=$this->CI->jsapiticketclass->get_jsapi_ticket();
        $timestamp = time();
        $wxnonceStr = "uvxwhhrt5689hdhdg8569";
        $wxticket = $ticket;
        $wxOri = sprintf("jsapi_ticket=%s&noncestr=%s&timestamp=%s&url=%s",
            $wxticket, $wxnonceStr, $timestamp,$url
        );
        $wxSha1 = sha1($wxOri);
        $data=array(
            "timestamp"=>$timestamp,
            "nonceStr"=>$wxnonceStr,
            "signature"=>$wxSha1
        );
        return $data;
    }
}